home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1988. All rights are reserved.
- */
-
- #include <em.h>
-
- #include <h19.h>
- #include <macdefs.h>
- #include <rcodes.h>
-
- /* globals */
- char vt100AVOid[] = "\033[?1;2c"; /* response to whoami request */
- char vt102id[] = "\033[?6c"; /* response to whoami request */
- char vt220id[] = "\033[?62;1;2c"; /* response to whoami request, level 2
- with 7-bit controls & printer port */
-
- char imokstr[] = "\033[0n";
-
- extern int (*screen_upd)();
-
- extern short usedsdraw; /* set through emprep() */
- extern short emupdwait; /* set through emprep() */
-
- /* make an array for mapping special VT chars into our font... */
-
- #ifdef MERGEDVTCHARS
-
- unsigned char vtfontmap[32] = {
- 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
- 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 196, 185, 197, 0
- };
-
- #define FIRSTVTSYM 96 /* first special font symbol of 31 such... */
- #define LASTVTSYM 126
-
- #endif
-
- /* character at a time interface */
-
- vt100(thechar)
- char thechar;
- {
- vt100str(&thechar, 1);
- }
-
-
- /* string interface */
-
- vt100str(strp, ccount)
- register unsigned char * strp;
- short ccount;
- {
- register unsigned char * endp = strp + ccount;
- register unsigned char thechar;
- register short thearg;
- short count;
-
- emprep();
- if (usedsdraw) {
- emdp->inselection = chkinvert();
- setascattr_ds(attrib, emdp->inselection);
-
- }
-
- while (strp < endp) {
- thechar = *strp++; /* we assume high bit off... */
- if (vtmode == NORMMODE) {
- /* NORMMODE interpreted here to avoid switch overhead */
- /* draw character if alphanumeric */
- if (emdp->emliteral || (thechar >= 0x20 && thechar != 0x7f)) {
- if (emdp->wrapped) {
- /* do the scroll we delayed earlier */
- wrapdown();
- }
- #ifdef BETTERLITERAL
- if (emdp->emliteral) {
- /* remap control chars so they are not interpreted */
- if (thechar == CR) {
- thechar = 0x86;
- }
- else if (thechar == HTAB) {
- thechar = 0x84;
- }
- }
- #endif
- if (inserton) {
- ins_char();
- }
- #ifdef MERGEDVTCHARS
- if (emdp->charset) {
- /* vt font in effect */
- if (thechar >= FIRSTVTSYM && thechar <= LASTVTSYM) {
- /* it's a special char, remap, otherwise leave it be */
- thechar = vtfontmap[thechar - FIRSTVTSYM];
- }
- }
- #endif
- *charp = thechar;
- *(charp + emdp->screensize) = attrib;
- if (emdp->matchinput) {
- /* we're trying to match input characters */
- if (matchtoken(thechar))
- resumetokens(emdp);
- }
- #ifdef FASTDRAW
- if (usedsdraw && !modflg) {
- /* we're using direct-to-screen drawing; if
- some QD has been used (e.g. jumpscroll) keep on using it */
- #ifdef NOMODFLGTEST
- /* if there's no !modflg test above, we need this... */
- if (modflg) {
- emrefresh(emwindow, TRUE);
- }
- #endif
- if (emdp->selrectvis) {
- if (emdp->inselection != chkinvert()) {
- if (emdp->inselection)
- emdp->inselection = FALSE;
- else
- emdp->inselection = TRUE;
- setascattr_ds(attrib, emdp->inselection);
- }
- }
- zapchar(thechar);
- clrflg &= ~modmask[ypos]; /* reset clear flag */
- }
- else {
- /* for quickdraw, draw when finished updating map
- if (inserton || count == 1)
- ch_draw_qd(thechar);
- else
- */
- modflg |= modmask[ypos];
- }
- #else
- modflg |= modmask[ypos];
- #endif
-
- /* adjust cursor position */
- if (xpos < lastcol) {
- xpos++;
- charp++;
- }
- else if (wrap_around) {
- emdp->wrapped = TRUE;
- /* wait to scroll up until next char received */
- }
- continue;
- }
- /* else if an ascii control character... */
- switch (thechar) {
- case 0x07: {
- /* BELL */
- if (!emdp->emdisable)
- beep();
- break;
- }
- case 0x08: {
- /* BS */
- if (emdp->wrapped)
- wrapdown();
- if (xpos > 0) {
- --xpos;
- --charp;
- }
- break;
- }
- case 0x09: {
- /* HTAB */
- vttab();
- break;
- }
- case 0x0d: {
- /* CR */
- emdp->wrapped = FALSE;
- charp -= xpos;
- xpos = 0;
- break;
- }
- case 0x0a:
- case 0x0b:
- case 0x0c: {
- /* LF */
- if (emdp->vtnewline) {
- /* do a CR if in newline mode */
- charp -= xpos;
- xpos = 0;
- emdp->wrapped = FALSE;
- }
- if (emdp->wrapped) {
- wrapdown();
- }
- else {
- if (ypos < emdp->scrollbottom) {
- charp += linelength;
- ypos++;
- }
- else {
- if (emdp->scrolltop == TOPROW
- && emdp->scrollbottom == emdp->lastrow) {
- (*emdp->scrollup)();
- }
- else
- del_lin(emdp->scrolltop);
- }
- }
- break;
- }
- case 0x0e: {
- /* SO, shift out G0 character set (select G1) */
- vtcharshift(TRUE);
- break;
- }
- case 0x0f: {
- /* SI, shift in G0 character set */
- vtcharshift(FALSE);
- break;
- }
- case 0x1b: {
- /* ESC */
- vtmode = VT_ESC;
- break;
- }
- case X_OFF: {
- break;
- }
- case X_ON: {
- break;
- }
- }
- #ifdef TESTBOUND
- testbound();
- #endif
- continue;
- }
- /* else interpret character according to proper mode */
- switch (vtmode) {
- /* do nothing for NORMMODE; interpreted above the switch */
- case VT_ESC: {
- vtmode = NORMMODE;
- switch (thechar) {
- case ESC: {
- /* 2 Escape characters: go into c19 file transfer mode */
- vtmode = CFTMODE;
- break;
- }
- case '[': {
- /* standard ANSI command */
- vtmode = VT_ANSI;
- if (emdp->argcount) {
- while (emdp->argcount)
- /* clear the old entries */
- emdp->argarr[emdp->argcount--] = 0;
- }
- emdp->argarr[0] = 0;
- argp = &emdp->argarr[0];
- break;
- }
- case '#': {
- /* interpret DEC private mode */
- vtmode = VT_POUND;
- break;
- }
- case '(': {
- vtmode = VT_LPAREN;
- break;
- }
- case ')': {
- vtmode = VT_RPAREN;
- break;
- }
- case ' ': {
- vtmode = VT_SPACE;
- break;
- }
- case 'E': {
- /* next line, do a CR Index */
- emdp->wrapped = FALSE;
- charp -= xpos;
- xpos = 0;
- }
- case 'D': {
- /* index */
- if (emdp->wrapped)
- wrapdown();
- if (ypos < emdp->scrollbottom) {
- ypos++;
- charp += linelength;
- }
- else {
- if (emdp->scrolltop == TOPROW
- && emdp->scrollbottom == emdp->lastrow) {
-
- (*emdp->scrollup)();
- }
- else
- del_lin(emdp->scrolltop);
- }
- break;
- }
- case 'M': {
- /* reverse index */
- if (emdp->wrapped)
- wrapdown();
- if (ypos == emdp->scrolltop)
- ins_lin(emdp->scrolltop);
- else if (ypos > 0) {
- --ypos;
- charp -= linelength;
- }
- break;
- }
- case '7': {
- /* save cursor position */
- emdp->ocharset = emdp->charset;
- emdp->oattrib = attrib;
- emdp->oxpos = xpos;
- emdp->oypos = ypos;
-
- emdp->ocharsetSO = emdp->charsetSO;
- emdp->owrapped = emdp->wrapped;
- emdp->odecom = emdp->decom;
- /* vt220 also selective erase mode */
- break;
- }
- case '8': {
- /* restore cursor position */
- emdp->charset = emdp->ocharset;
- attrib = emdp->oattrib;
- xpos = emdp->oxpos;
- ypos = emdp->oypos;
- charp = emdp->charr + xpos + (ypos * linelength);
-
- emdp->wrapped = emdp->owrapped;
- emdp->decom = emdp->odecom;
- emdp->charsetSO = emdp->ocharsetSO;
- emdp->inselection = chkinvert();
- #ifdef FASTDRAW
- setascattr_ds(attrib, emdp->inselection);
- #endif
- break;
- }
- case 'H': {
- /* set tab stop at cursor */
- emdp->tabset[xpos] = TRUE;
- break;
- }
- case '=': {
- /* enter alt keypad mode */
- if (!emdp->vtkeypad)
- emdp->vtaltkeypad = TRUE;
- break;
- }
- case '>': {
- /* exit alt keypad mode */
- if (!emdp->vtkeypad)
- emdp->vtaltkeypad = FALSE;
- break;
- }
- case 'c': {
- /* Reset to Initial state */
- vt100reset();
- #ifdef FASTDRAW
- setascattr_ds(attrib, emdp->inselection);
- #endif
- break;
- }
- }
- #ifdef TESTBOUND
- testbound();
- #endif
- break;
- }
- case VT_ANSI: {
- short index;
-
- if ( (thechar >= '0') && (thechar <= '9') ) {
- /* another numeric arg char */
- *argp = (*argp * 10) + (thechar - '0');
- break;
- }
- if (thechar == ';') {
- if (emdp->argcount < MAXARGS) {
- argp++;
- emdp->argcount++;
- }
- break;
- }
- if (thechar < ' ') {
- /* an ASCII control char which needs to be interpreted */
- vtcontrol(thechar);
- break;
- }
- if (thechar == '?') {
- /* DEC private mode, ignore any args */
- if (emdp->argcount) {
- while (emdp->argcount)
- emdp->argarr[emdp->argcount--] = 0;
- }
- emdp->argarr[0] = 0;
- argp = &emdp->argarr[0];
- vtmode = VT_QMARK;
- break;
- }
- emdp->argcount++;
- vtmode = NORMMODE;
- thearg = emdp->argarr[0]; /* current arg, default for CUP etc. */
-
- switch (thechar) {
- case 'A': {
- /* cursor up */
- if (thearg == 0)
- thearg = 1;
- #ifdef CURMOWRAP
- if (emdp->wrapped)
- wrapdown();
- #endif
- /* TODO should scrolltop references check for decom? */
- if (thearg > ypos - emdp->scrolltop)
- thearg = ypos - emdp->scrolltop;
- if (thearg <= 0)
- break;
-
- ypos -= thearg;
- charp -= thearg * linelength;
- break;
- }
- case 'B': {
- /* cursor down */
- if (thearg == 0)
- thearg = 1;
- #ifdef CURMOWRAP
- if (emdp->wrapped)
- wrapdown();
- #endif
- if (ypos + thearg > emdp->scrollbottom)
- thearg = emdp->scrollbottom - ypos;
- if (thearg <= 0)
- break;
-
- ypos += thearg;
- charp += thearg * linelength;
- break;
- }
- case 'C': {
- /* cursor right */
- if (thearg == 0)
- thearg = 1;
- #ifdef CURMOWRAP
- if (emdp->wrapped)
- wrapdown();
- #endif
- if (xpos + thearg > lastcol)
- thearg = lastcol - xpos;
- if (thearg <= 0)
- break;
-
- xpos += thearg;
- charp += thearg;
- break;
- }
- case 'D': {
- /* cursor left */
- if (thearg == 0)
- thearg = 1;
- #ifdef CURMOWRAP
- if (emdp->wrapped)
- wrapdown();
- #else
- emdp->wrapped = FALSE;
- #endif
- if (thearg > xpos)
- thearg = xpos;
-
- xpos -= thearg;
- charp -= thearg;
- break;
- }
- case 'g': {
- /* clear tab(s) */
- if (thearg == 0) {
- emdp->tabset[xpos] = FALSE;
- }
- else if (thearg == 3) {
- /* clear all tabs */
- for (count = 0; count < linelength; ) {
- emdp->tabset[count++] = FALSE;
- }
- }
- break;
- }
- case 'H':
- case 'f': {
- /* move cursor */
- /* set the y position first */
- emdp->wrapped = FALSE;
-
- if (thearg)
- --thearg;
-
- if (emdp->decom) {
- /* in origin mode, correct the argument */
- thearg += emdp->scrolltop;
- if (thearg < emdp->scrolltop)
- /* keep within top margin */
- thearg = emdp->scrolltop;
- else if (thearg > emdp->scrollbottom)
- /* keep within bottom margin */
- thearg = emdp->scrollbottom;
- }
- else {
- if (thearg < 0)
- /* keep within top margin */
- thearg = 0;
- else if (thearg > emdp->lastrow)
- /* keep within bottom margin */
- thearg = emdp->lastrow;
- }
- ypos = thearg;
-
- /* now set the x position */
- thearg = emdp->argarr[1];
- if (thearg)
- --thearg;
- if (thearg >= linelength) {
- thearg = lastcol;
- }
- xpos = thearg;
- charp = emdp->charr + (ypos * linelength) + xpos;
- break;
- }
- case 'J': {
- /* erase screen */
- if (emdp->wrapped)
- wrapdown();
- switch (thearg) {
- case 0: {
- /* clear to end of screen */
- if (emdp->selrectvis || bkrd_act || emupdwait) {
- /* must redraw through upd */
- for (count = ypos; count <= emdp->lastrow; count++)
- modflg |= modmask[count];
- }
- else {
- clr_eol();
-
- emdp->bigrect.top = (ypos + 1) * emdp->lineheight + emdp->voffset;
- clearrect(&emdp->bigrect);
- emdp->bigrect.top = emdp->voffset;
-
- /* set the line-cleared flag */
- count = ypos;
- if (xpos != 0)
- count++;
- for (; count <= emdp->lastrow; count++)
- clrflg |= modmask[count];
- }
- /* blank out the screen map to the end of screen */
- if (ypos == 0 && xpos == 0) {
- /* save the screen before it gets overwritten */
- if (!emdp->ibm_keymode)
- savescreen();
- }
- /* TODO should saveline()s?
- if (emdp->logerase)
- saveline(charp, emdp->charrend - charp);
- */
- c19_blank(charp, emdp->charrend - charp);
- break;
- }
- case 1: {
- /* clear screen up to & including cursor position */
- Rect trect;
-
- if (emdp->selrectvis || bkrd_act || emupdwait) {
- /* must redraw through upd */
- for (count = 0; count <= ypos; count++)
- modflg |= modmask[count];
- }
- else {
- emdp->bigrect.bottom = ypos * emdp->lineheight;
- clearrect(&emdp->bigrect);
- emdp->bigrect.bottom = emdp->bottommarg;
-
- trect.top = ypos * emdp->lineheight + emdp->voffset;
- trect.left = emdp->hoffset;
- trect.bottom = trect.top + emdp->lineheight;
- trect.right = ((xpos + 1) * fontwidth) + emdp->hoffset;
- clearrect(&trect);
-
- /* set the line-cleared flag */
- for (count = 0; count < ypos; count++)
- clrflg |= modmask[count];
- if (xpos == lastcol)
- /* last line was completely cleared also */
- clrflg |= modmask[count];
- }
- if (ypos == emdp->lastrow && xpos == lastcol) {
- /* save the screen before it gets overwritten */
- if (!emdp->ibm_keymode)
- savescreen();
- }
- /*
- else if (emdp->logerase)
- saveline(charp, emdp->charrend - charp);
- */
- c19_blank(&emdp->charr[0], charp - emdp->charr + 1);
- break;
- }
- case 2: {
- /* reset: clear screen */
- attrib &= NOATTR;
- if (emdp->selrectvis || bkrd_act || emupdwait) {
- /* TODO should have selerase() */
- modflg = SCRALLMOD;
- }
- else {
- clearrect(&emdp->bigrect);
- clrflg = SCRALLMOD;
- }
- #ifdef FASTDRAW
- setascattr_ds(attrib, emdp->inselection);
- #endif
- if (!emdp->ibm_keymode)
- savescreen();
- /* save the screen before it gets overwritten */
-
- /* blank out the screen map */
- c19_blankmap(&emdp->charr[0]);
- break;
- }
- }
- break;
- }
- case 'K': {
- /* erase line */
- if (emdp->wrapped)
- wrapdown();
- switch (thearg) {
- case 0: {
- clr_eol();
- break;
- }
- case 1: {
- clrtocurs();
- break;
- }
- case 2: {
- /* clear current line */
- Rect temprect;
- char * destp;
-
- #ifdef FASTDRAW
- if (emdp->selrectvis || bkrd_act || emupdwait) {
- /* must redraw through upd */
- modflg |= modmask[ypos];
- }
- else {
- temprect.top = ypos * emdp->lineheight + emdp->voffset;
- temprect.left = emdp->hoffset;
- temprect.bottom = temprect.top + emdp->lineheight;
- temprect.right = emdp->rightmarg;
- clearrect(&temprect);
-
- clrflg |= modmask[ypos];
- }
- #else
- modflg |= modmask[ypos];
- #endif
- destp = emdp->charr + ypos * linelength;
- if (!emdp->ibm_keymode)
- saveline(destp, linelength);
- /* save the line if needed before it gets overwritten */
- c19_blank(destp, linelength);
- break;
- }
- }
- break;
- }
- case 'L': {
- /* insert line */
- if (emdp->wrapped)
- wrapdown();
- if (thearg == 0)
- thearg = 1;
- while (thearg--)
- ins_lin(ypos);
- charp -= xpos;
- xpos = 0;
- break;
- }
- case 'M': {
- /* delete line */
- if (emdp->wrapped)
- wrapdown();
- if (thearg == 0)
- thearg = 1;
- while (thearg--)
- del_lin(ypos);
- charp -= xpos;
- xpos = 0;
- break;
- }
- case 'P': {
- /* delete char */
- if (emdp->wrapped)
- wrapdown();
- if (thearg == 0)
- thearg = 1;
- while (thearg--)
- del_char();
- break;
- }
- case '@': {
- /* insert char */
- if (emdp->wrapped)
- wrapdown();
- if (thearg == 0)
- thearg = 1;
- while (thearg--)
- ins_char();
- break;
- }
- /* vt220 stuff not here:
- 'X' erase n chars
- ?K selective erase in line
- ?J selective erase in display
-
- CSI?5 i auto print when cursor moves off line w/ LF, tab, w
- CSI?4 i auto print off
- CSI 5 i print without display
- CSI 4 i turn off print without display
- CSI ? 1 i print display line w/ cursor
- CSI i print screen
- CSI 0 i ditto
-
- */
- case 'i': {
- /* print screen without a dialog */
- if ((thearg == 0)) {
- QDprinttext(RF_PRINTSCREEN, FALSE);
- }
- break;
- }
- case 'c': {
- /* whoami */
- if ((thearg == 0)) {
- if (emdp->disableterm[emdp->termtype]) {
- /* hey, we're not currently identified!
- This happens w/ VAX/Wollongong TCP... */
- if (!emdp->disableterm[TERM_VT100]) {
- (*emdp->sendstr)(vt100AVOid);
- }
- else if (!emdp->disableterm[TERM_VT102]) {
- (*emdp->sendstr)(vt102id);
- }
- else if (!emdp->disableterm[TERM_VT220]) {
- (*emdp->sendstr)(vt220id);
- }
- else {
- /* assume we're a VT100 */
- (*emdp->sendstr)(vt100AVOid);
- }
- }
- else {
- switch (emdp->termtype) {
- case TERM_VT100:
- (*emdp->sendstr)(vt100AVOid);
- break;
- case TERM_VT102:
- (*emdp->sendstr)(vt102id);
- break;
- case TERM_VT220:
- (*emdp->sendstr)(vt220id);
- break;
- }
- }
- }
- break;
- }
- case 'h': {
- /* set ANSI modes */
- if (thearg == 4) {
- /* insert mode */
- inserton = TRUE;
- }
- else if (thearg == 20)
- /* CR = CR-LF mode */
- emdp->vtnewline = TRUE;
- break;
- }
- case 'l': {
- /* reset ANSI modes */
- if (thearg == 4) {
- /* insert mode */
- inserton = FALSE;
- }
- else if (thearg == 20) {
- /* CR = CR-LF mode */
- emdp->vtnewline = FALSE;
- }
- break;
- }
- case 'm': {
- /* set attributes */
- for (index = 0; index < emdp->argcount; index++) {
- switch(emdp->argarr[index]) {
- case 0: {
- /* attributes off */
- attrib &= NOATTR;
- break;
- }
- case 1: {
- /* bold */
- attrib |= BOLD;
- break;
- }
- case 4: {
- /* underscore */
- attrib |= UNDERSCORE;
- break;
- }
- case 5: {
- /* blink video */
- attrib |= BLINK;
- break;
- }
- case 7: {
- /* reverse video */
- attrib |= REVERSE;
- break;
- }
- /* vt220 compatibility */
- case 22: {
- /* bold */
- attrib &= ~BOLD;
- break;
- }
- case 24: {
- /* underscore */
- attrib &= ~UNDERSCORE;
- break;
- }
- case 25: {
- /* blink video */
- attrib &= ~BLINK;
- break;
- }
- case 27: {
- /* reverse video */
- attrib &= ~REVERSE;
- break;
- }
- }
- }
- #ifdef FASTDRAW
- if (emdp->dsdraw)
- setascattr_ds(attrib, emdp->inselection);
- #endif
- break;
- }
- case 'n': {
- char cursorstr[16];
-
- if (thearg == 5) {
- /* whoami */
- (*emdp->sendstr)(imokstr);
- }
- else if (thearg == 6) {
- /* report cursor position */
- int nypos;
-
- if (emdp->decom)
- nypos = ypos - emdp->scrolltop;
- else
- nypos = ypos;
-
- sprintf(cursorstr, "\033[%d;%dR", (int) ++nypos, (int) xpos + 1);
- (*emdp->sendstr)(cursorstr);
- }
- break;
- }
- case 'q': {
- /* programmable LEDS 0 = reset */
- break;
- }
- case 'r': {
- /* set scrolling region */
-
- if (emdp->wrapped)
- wrapdown();
-
- if (emdp->argarr[0])
- --emdp->argarr[0];
-
- if (emdp->argarr[1])
- --emdp->argarr[1];
- else
- emdp->argarr[1] = emdp->lastrow;
-
- if (emdp->argarr[1] > emdp->lastrow
- || emdp->argarr[1] <= emdp->argarr[0])
- /* bad arguments */
- break;
-
- emdp->scrolltop = emdp->argarr[0];
- emdp->scrollbottom = emdp->argarr[1];
- emdp->scrollrect.top = emdp->scrolltop * emdp->lineheight + emdp->voffset;
- emdp->scrollrect.bottom = (emdp->scrollbottom + 1) * emdp->lineheight + emdp->voffset;
-
- xpos = 0;
- if (emdp->decom) {
- ypos = emdp->scrolltop;
- charp = emdp->charr + (emdp->scrolltop * linelength);
- }
- else {
- ypos = 0;
- charp = emdp->charr;
- }
- break;
- }
- case 'x': {
- /* request terminal parameters, report */
- (*emdp->sendstr)("\033[");
- if (thearg == 0)
- (*emdp->sendchar)('2');
- else
- (*emdp->sendchar)('3');
- (*emdp->sendstr)(";1;1;0;1;0x");
- /* report; no parity; 8 bits; 50 baud (limit nulls!); clkmul; junk; x */
- break;
- }
- case 'y': {
- /* confidence test; reset if second arg == 0 */
- if (emdp->argcount == 2
- && emdp->argarr[0] == 2
- && emdp->argarr[1] == 0)
- vt100reset();
- break;
- }
- }
- #ifdef TESTBOUND
- testbound();
- #endif
-
- break;
- }
- case VT_QMARK: {
- int index;
-
- if (thechar < ' ') {
- /* an ASCII control char which needs to be interpreted */
- vtcontrol(thechar);
- break;
- }
- if ((thechar <= '9') && (thechar >= '0')) {
- *argp = (*argp * 10) + (thechar - '0');
- break;
- }
- if (thechar == ';') {
- if (emdp->argcount < MAXARGS) {
- argp++;
- emdp->argcount++;
- }
- break;
- }
- emdp->argcount++;
- vtmode = NORMMODE;
- if (thechar == 'h') {
- /* set DEC private mode mode on */
-
- /* unimplemented:
- 3 = column mode (80/132) columns
- 5 = screen mode (reverse)
- 8 auto repeat
- 9 = interlace
- */
- for (index = 0; index < emdp->argcount; index++) {
- switch (emdp->argarr[index]) {
- case 1: {
- /* DECCKM cursor key mode */
- if (!emdp->vtkeypad)
- emdp->vtaltcursor = 'O';
- break;
- }
- case 2: {
- /* ANSI mode */
- break;
- }
- case 3: {
- /* DECCOLM 80 columns */
- emdp->linelength = 132;
- useqd(emdp);
- /* go into QuickDraw mode temporarily, since a
- refresh might occur which would not be
- supported by the useds() routines */
- vt100reset();
- setscreensize(emdp->fontsize);
- break;
- }
- case 4: {
- /* jump scroll mode */
- #ifdef VTJUMPSCROLL
- emdp->vtjumpscroll = FALSE;
- #endif
- break;
- }
- case 6: {
- /* DEC origin mode */
- emdp->decom = TRUE;
- charp = emdp->charr + (emdp->scrolltop * linelength);
-
- ypos = emdp->scrolltop;
- xpos = 0;
- break;
- }
- case 7: {
- /* auto wrap around */
- wrap_around = TRUE;
- break;
- }
- }
- }
- }
- else if (thechar == 'l') {
- /* reset mode */
- for (index = 0; index < emdp->argcount; index++) {
- switch (emdp->argarr[index]) {
- case 1: {
- /* DECCKM cursor key mode */
- if (!emdp->vtkeypad)
- emdp->vtaltcursor = '[';
- break;
- }
- case 2: {
- /* VT52 mode */
- mode = NORMMODE;
- emdp->em = h19;
- emdp->emstr = h19str;
- emend(); /* emprep will be called again */
- h19str(strp, endp - strp);
- /* hand over remaining data */
- return(0);
- break;
- }
- case 3: {
- /* DECCOLM 80 columns */
- emdp->linelength = 80;
- useqd(emdp);
- vt100reset();
- setscreensize(emdp->fontsize);
- break;
- }
- case 4: {
- /* DECSCLM scroll mode */
- #ifdef VTJUMPSCROLL
- /* slows down scrolling too much */
- emdp->vtjumpscroll = TRUE;
- #endif
- break;
- }
- case 6: {
- /* DEC origin mode */
- emdp->decom = FALSE;
- charp = emdp->charr;
- ypos = 0;
- xpos = 0;
- break;
- }
- case 7: {
- wrap_around = FALSE;
- break;
- }
- }
- }
- }
- #ifdef TESTBOUND
- testbound();
- #endif
- break;
- }
- case VT_POUND: {
- /* DEC double-width, double-height, test, etc. */
- if (thechar == '8') {
- /* DECALN alignment feature: fill screen with E's */
- decaln();
- }
- vtmode = NORMMODE;
- break;
- }
- case VT_LPAREN: {
- if (thechar == '0') {
- /* use vt graphic characters */
- emdp->charsetG0 = VTFONT;
- }
- else {
- /* return to norm font */
- emdp->charsetG0 = NORMFONT;
- }
- if (!emdp->charsetSO) {
- vtcharshift(FALSE);
- }
- vtmode = NORMMODE;
- break;
- }
- case VT_RPAREN: {
- if (thechar == '0') {
- /* use vt graphic characters */
- emdp->charsetG1 = VTFONT;
- }
- else {
- /* return to norm font */
- emdp->charsetG1 = NORMFONT;
- }
- if (emdp->charsetSO) {
- vtcharshift(TRUE);
- }
- vtmode = NORMMODE;
- break;
- }
- case VT_SPACE: {
- /* 'F' is 7-bit control mode, 'G' is 8-bit (CSI) mode
- so the terminal doesn't send <ESC>[
- so just throw the next character out */
- vtmode = NORMMODE;
- break;
- }
- case CFTMODE: {
- cft(thechar);
- break;
- }
- case CFT2MODE: {
- cft2(thechar);
- break;
- }
- case C19FTMODE: {
- c19ft(thechar);
- break;
- }
- default: {
- vtmode = NORMMODE;
- break;
- }
- }
- /* continue character loop */
- }
- newcursor();
- emend();
- }
-
-
- /* make the emulator a vt100 */
-
- vtinit()
- {
- short count;
- short tab = 8; /* first tab location */
-
- emdp->mode = VT100MODE;
- emdp->vtmode = NORMMODE;
-
- for (count = linelength / 8; --count > 0; tab += 8) {
- /* set tab stops */
- emdp->tabset[tab] = TRUE;
- }
- emdp->vtaltcursor = 'O';
- emdp->vtaltkeypad = FALSE;
-
- /* set keypad to user preference if requested */
- switch (emdp->vtkeypad) {
- case KEYPAD1: {
- /* user wants calculator */
- emdp->vtaltkeypad = FALSE;
- break;
- }
- case KEYPAD2: {
- /* user wants application */
- emdp->vtaltkeypad = TRUE;
- break;
- }
- case KEYPAD3: {
- /* user wants application alternate */
- emdp->vtaltkeypad = TRUE;
- emdp->vtaltcursor = '[';
- break;
- }
- }
-
- emdp->scrollrect.bottom = emdp->bottommarg;
- emdp->scrollrect.right = emdp->rightmarg;
-
- emdp->decom = FALSE;
- emdp->vtnewline = FALSE;
- emdp->wrapped = FALSE;
-
- /* character set state */
- emdp->charsetSO = FALSE; /* G0 set shifted out? */
- emdp->charsetG0 = NORMFONT; /* G0 character set */
- emdp->charsetG1 = NORMFONT; /* G1 character set */
- emdp->charset = 0;
-
- /* reset scrolling region */
- emdp->scrolltop = TOPROW;
- emdp->scrollbottom = emdp->lastrow;
- emdp->scrollrect.top = emdp->voffset;
- emdp->scrollrect.left = emdp->hoffset;
- emdp->scrollrect.bottom = emdp->bottommarg;
- emdp->scrollrect.right = emdp->rightmarg;
- }
-
-
- /* reset the state of the vt100 */
-
- vt100reset()
- {
- short count;
-
- h19reset(); /* reset the "vt52" also */
-
- for (count = 0; count < linelength; ) {
- /* clear all tabs */
- emdp->tabset[count++] = FALSE;
- }
- while (emdp->argcount)
- /* clear the old entries */
- emdp->argarr[emdp->argcount--] = 0;
- emdp->argp = &emdp->argarr[0];
-
- vtinit();
-
- emdp->mode = VT100MODE;
- setcontext(emdp); /* update globals */
- }
-
-
- testbound()
- {
- if (xpos < 0 || xpos > linelength
- || ypos < 0 || ypos > emdp->lastrow
- || charp < emdp->charr || charp >= emdp->charrend)
- badbound();
- }
-
-
- /* a label on which to set a breakpoint */
-
- badbound()
- {
- }
-
- /* a close duplicate of the switch in the NORMMODE state */
-
- vtcontrol(thechar)
- register unsigned char thechar;
- {
- switch (thechar) {
- case 0x07: {
- /* BELL */
- if (!emdp->emdisable)
- beep();
- break;
- }
- case 0x08: {
- /* BS */
- if (emdp->wrapped)
- wrapdown();
- if (xpos > 0) {
- --xpos;
- --charp;
- }
- break;
- }
- case 0x09: {
- /* HTAB */
- vttab();
- break;
- }
- case 0x0d: {
- /* CR */
- charp -= xpos;
- xpos = 0;
- emdp->wrapped = FALSE;
- break;
- }
- case 0x0a:
- case 0x0b:
- case 0x0c: {
- /* LF, VT, & FF */
- if (emdp->vtnewline) {
- /* do a CR if in newline mode */
- charp -= xpos;
- xpos = 0;
- emdp->wrapped = FALSE;
- }
- if (emdp->wrapped) {
- wrapdown();
- }
- else {
- if (ypos < emdp->scrollbottom) {
- charp += linelength;
- ypos++;
- }
- else {
- if (emdp->scrolltop == TOPROW && emdp->scrollbottom == emdp->lastrow) {
- (*emdp->scrollup)();
- }
- else
- del_lin(emdp->scrolltop);
- }
- }
- break;
- }
- case 0x0e: {
- /* SO, shift out G0 character set (select G1) */
- vtcharshift(TRUE);
- break;
- }
- case 0x0f: {
- /* SI, shift in G0 character set */
- vtcharshift(FALSE);
- break;
- }
- case 0x1b: {
- /* ESC--do nothing in this mode */
- break;
- }
- case 24:
- case 26: {
- /* CAN / SUB cancel current escape sequence */
- vtmode = NORMMODE;
- break;
- }
- case X_OFF: {
- break;
- }
- case X_ON: {
- break;
- }
- }
- }
-
-
- /* fill the screen with E's to help "align the screen"--heh, heh... */
-
- decaln()
- {
- register char * thep = &emdp->charr[0];
-
- modflg = SCRALLMOD;
- while (thep < emdp->charrend) {
- *thep++ = 'E';
- }
- }
-
-
- /* the cursor was at the end of line in the would-wrap state */
-
- wrapdown()
- {
- emdp->wrapped = FALSE;
- charp -= xpos;
- xpos = 0;
- if (ypos < emdp->scrollbottom) {
- charp += linelength;
- ypos++;
- }
- else {
- if (emdp->scrolltop == TOPROW && emdp->scrollbottom == emdp->lastrow) {
- (*emdp->scrollup)();
- }
- else
- del_lin(emdp->scrolltop);
- }
- }
-
-
-
- vtcharshift(state)
- int state;
- {
- emdp->charsetSO = state;
- if (state)
- emdp->charset = emdp->charsetG1;
- else
- emdp->charset = emdp->charsetG0;
-
- #ifndef MERGEDVTCHARS
- /* separate attribute not needed if character sets merged... */
- attrib &= VTATTR;
- attrib |= emdp->charset;
-
- #ifdef FASTDRAW
- setascattr_ds(attrib, emdp->inselection);
- #endif
-
- #endif
- }
-
-
-
- vttab()
- {
- short shift;
-
- if (emdp->wrapped)
- wrapdown();
-
- /* go to next tab */
- for (shift = xpos; ++shift < linelength;) {
- if (emdp->tabset[shift]) {
- charp += shift - xpos;
- xpos = shift;
- break;
- }
- }
- /* no tab, go to end of line */
- if (shift == linelength) {
- charp += linelength - 1 - xpos;
- xpos = linelength - 1;
- }
- }